﻿namespace ctolua.Models.Areas
{
    public enum RecAreaType
    {
        左下起始 = 1,
        中心点起始 = 2,
    }
    /// <summary>
    /// 矩形区域
    /// </summary>
    public class MRecArea : MArea
    {
        private RecArea _recArea;
        /// <summary>
        /// 矩形区域实体
        /// </summary>
        public RecArea recArea
        {
            get => this._recArea;
            set
            {
                this._recArea = value;
                this.area = value;
            }
        }
        private double _length;
        /// <summary>
        /// 矩形区域长
        /// </summary>
        public double length
        {
            get => this._length;
            set
            {
                _length = value;
                game_api.set_rect_area_radius(this.recArea, py.Fix32(value), py.Fix32(this.width));
            }
        }
        private double _width;
        /// <summary>
        /// 矩形区域宽
        /// </summary>
        public double width
        {
            get => this._width;
            set
            {
                _width = value;
                game_api.set_rect_area_radius(this.recArea, py.Fix32(this.length), py.Fix32(value));
            }
        }
        /// <summary>
        /// 最小x
        /// </summary>
        public double min_x => game_api.get_rect_area_min_x(this.recArea).@float();
        /// <summary>
        /// 最小y
        /// </summary>
        public double min_y => game_api.get_rect_area_min_y(this.recArea).@float();
        /// <summary>
        /// 最大x
        /// </summary>
        public double max_x => game_api.get_rect_area_max_x(this.recArea).@float();
        /// <summary>
        /// 最大y
        /// </summary>
        public double max_y => game_api.get_rect_area_max_y(this.recArea).@float();


        /// <summary>
        /// 矩形区域内单位数量
        /// </summary>
        /// <returns>单位数量</returns>
        public int? get_unit_num_in_rec_area => game_api.get_unit_num_in_rec_area(this.recArea);
        /// <summary>
        /// 矩形区域内所有未销毁单位
        /// </summary>
        /// <returns>单位组</returns>
        public UnitGroup get_unit_group_in_rec_area => game_api.get_unit_group_in_rec_area(this.recArea);
        /// <summary>
        /// 矩形区域内所有物品
        /// </summary>
        /// <returns>物品组</returns>
        public ItemGroup get_item_group_in_rec_area => game_api.get_item_group_in_rec_area(this.recArea);
        /// <summary>
        /// 矩形区域是否存在
        /// </summary>
        /// <returns>是否存在</returns>
        public bool? is_null => game_api.rect_area_is_exist(this.recArea);

        /// <summary>
        /// 返回矩形区域内随机点
        /// </summary>
        /// <returns>随机点</returns>
        public MPoint get_random_point_in_rec_area => new MPoint(game_api.get_random_point_in_rec_area(this.recArea));
        /// <summary>
        /// 返回矩形区域中心点
        /// </summary>
        /// <returns>中心点</returns>
        public MPoint get_rec_center_point => new MPoint(game_api.get_rec_center_point(this.recArea));
        public MRecArea(RecArea recArea)
        {
            this.recArea = recArea;
        }
        /// <summary>
        /// 通过区域ID返回矩形区域
        /// </summary>
        /// <param name="res_id ">  区域ID   </param>
        public MRecArea(int res_id)
        {
            this.recArea = game_api.get_rec_area_by_res_id(res_id);
        }
        /// <summary>
        /// 创建矩形区域
        /// </summary>
        /// <param name="point ">  起始点   </param>
        /// <param name="width ">  宽   </param>
        /// <param name="height ">  高   </param>
        public MRecArea(RecAreaType type, Point point, double width, double height)
        {
            if (type == RecAreaType.左下起始)
            {
                this.recArea = game_api.create_new_rec_area(point, py.Fix32(width), py.Fix32(height));
            }
            else
            {
                this.recArea = game_api.create_rect_area_by_center(point, py.Fix32(width), py.Fix32(height));
            }

        }
        /// <summary>
        /// 创建矩形区域
        /// </summary>
        /// <param name="point_begin ">  起始点   </param>
        /// <param name="point_end ">  终点   </param>
        public MRecArea(Point point_begin, Point point_end)
        {
            this.recArea = game_api.create_rec_area_from_two_points(point_begin, point_end);
        }

        /// <summary>
        /// 点是否在矩形区域内
        /// </summary>
        /// <param name="point ">  点   </param>
        /// <returns>点是否在矩形区域内</returns>
        public bool? judge_point_in_rec_area(Point point) => game_api.judge_point_in_rec_area(point, this.recArea);
        /// <summary>
        /// 矩形区域是否拥有某tags
        /// </summary>
        /// <param name="tag ">  tag   </param>
        /// <returns>布尔值</returns>
        public bool? if_rect_area_has_tag(string tag) => game_api.if_rect_area_has_tag(this.recArea, tag);
        /// <summary>
        /// 设置矩形区域内视野情况
        /// </summary>
        /// <param name="player ">  玩家   </param>
        /// <param name="is_vision ">  布尔变量   </param>
        /// <param name="is_vision_true ">  布尔变量   </param>
        /// <returns>矩形区域</returns>
        public void set_rect_vision_visibility(Role player, bool? is_vision, bool? is_vision_true) => game_api.set_rect_vision_visibility(this.recArea, player, is_vision, is_vision_true);


        /// <summary>
        /// 根据tag获取对应的矩形区域
        /// </summary>
        /// <param name="tag"> tag </param>
        /// <returns>列表</returns>
        public static dynamic get_rect_areas_by_tag(string tag) => game_api.get_rect_areas_by_tag(tag);
        /// <summary>
        /// 最近创建的矩形区域
        /// </summary>
        /// <returns>矩形区域</returns>
        public static MRecArea get_rec_area_last_created() => new MRecArea(game_api.get_rec_area_last_created());
        /// <summary>
        /// 获取可用地图范围
        /// </summary>
        /// <returns>区域</returns>
        public static MRecArea get_usable_map_range() => new MRecArea(game_api.get_usable_map_range());
    }
}
